package com.zhp.service.impl;

import com.zhp.dao.OrderDao;
import com.zhp.dao.impl.OrderDaoImpl;
import com.zhp.pojo.HOrder;
import com.zhp.service.OrderService;
import com.zhp.service.UserService;

import java.util.Date;
import java.util.List;

/**
 * @Author Lone Ranger
 */
public class OrderServiceImpl implements OrderService {
    OrderDao orderDao = new OrderDaoImpl();
    UserService userService = new UserServiceImpl();
    @Override
    public boolean checkData(String odate, String edid, String sjdid) {

        // 获取此医生最大可预约人数
        int dnum = userService.getDoctorDnum(edid);

        int yyztid = 22; // 22为已付款

        int payOrder = orderDao.getPayOrderCount(odate,edid,sjdid,22);
        if(dnum - payOrder >0){
            return true;
        }
        return false;
    }

    @Override
    public int addOrder(HOrder hOrder) {
        return orderDao.addOrder(hOrder);
    }

    @Override
    public int updateOrderStatus(int oid, Integer yyztid) {
        return orderDao.updateOrderStatus(oid,yyztid);
    }

    @Override
    public List<HOrder> findOrderByUdid(Integer did) {
        return orderDao.findOrderByUdid(did);
    }

    @Override
    public int updateOrderByType(int oid, int yyztid, int type, Integer did, Date date) {
        // 预约中的取消
        if (type == 1){
            return this.updateOrderStatus(oid, yyztid);
        }
        // 预约中的付款
        if (type == 2){
            return this.updateOrderStatus(oid, yyztid);
        }
        // 预约中的取消
        if (type == 3){
            // 判断是否能取消

            return this.updateOrderStatus(oid, yyztid);
        }
        // 预约中的完成
        if (type == 4){
            return this.updateOrderStatus(oid, yyztid);
        }
        return 0;

    }
}
